﻿@{
    ViewBag.Title = "工作类型";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<script>
    var keyValue = request('keyValue');
    var _TypeRoleId = request('TypeRoleId');
    var EnCode = request('EnCode');
    var _RoleId = "";
    var _ItemId = "", _TypeId = "";
    $(function () {
        initControl();
    })
    //初始化控件
    function initControl() {
        //岗位
        $("#Role").ComboBoxTree({
            url: "../../BaseManage/Post/GetTreeJson",
            description: "==请选择==",
            height: "150px",
            click: function (item) {
                if (item.id != _RoleId) {
                    _RoleId = item.id;
                }
            }
        });

        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../SystemManage/DataItemDetail/GetForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                    
                    _ItemId = data.ItemId;
                }
            });
        }
        if (!!_TypeRoleId) {
            $.SetForm({
                url: "../../DailyEventManage/OpenShop/GetTypeRole",
                param: { keyValue: _TypeRoleId },
                success: function (data) {
                    $("#Role").ComboBoxTreeSetValue(data.RoleId);
                    $("#form1").SetWebControls(data);
                    _RoleId = data.RoleId;
                    _TypeId = data.TypeId;
                }
            });
        }

    }
    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var postData = $("#form1").GetWebControls(keyValue);
        postData["ItemDetailId"] = _TypeId;
        
        postData["ItemId"] = _ItemId;
        postData["ParentId"] = "0";
        postData["ItemValue"] = postData["ItemName"];
        postData["Category"] = 2;
        postData["RoleId"] = _RoleId;
        postData["TypeId"] = _TypeId;
        if (_TypeRoleId != "") postData["Id"] = _TypeRoleId;
        $.SaveForm({
            url: "../../DailyEventManage/OpenShop/TypeSaveForm?EnCode=" + EnCode + "&keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                top.frames["TypeForm"].$("#gridTable").trigger("reloadGrid");
            }
        });
    }
    //验证：项目值、项目名 不能重复
    function OverrideExistField(id, url) {
        $.ExistField(id, url, { itemId: itemId });
    }
</script>
<div style="margin-top: 20px; margin-right: 30px;">
    <input id="ParentId" type="hidden" />
    <input id="ItemId" type="hidden" />
    <table class="form">
        <tr>
            <td class="formTitle">类型名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="ItemName" type="text" onblur="OverrideExistField(this.id,'../../SystemManage/DataItemDetail/ExistItemName')" class="form-control" placeholder="请输入项目名" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">类型编号<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="ItemCode" type="text" onblur="OverrideExistField(this.id,'../../SystemManage/DataItemDetail/ExistItemValue')" class="form-control" placeholder="请输入项目值" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">执行岗位<font face="宋体">*</font></th>
            <td class="formValue">
                <div id="Role" type="select" class="ui-select" placeholder="请选择执行岗位" isvalid="yes" checkexpession="NotNull"></div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">排序</th>
            <td class="formValue">
                <input id="SortCode" type="text" class="form-control" isvalid="yes" checkexpession="Num" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" style="height: 37px;"></th>
            <td class="formValue">
                <input id="NeedSortFlag" type="checkbox" checked="checked" />
                项目是否需要排序
                <input id="EnabledMark" type="checkbox" checked="checked" />
                有效
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;">
                备注
            </th>
            <td class="formValue">
                <textarea id="Description" class="form-control" style="height: 70px;"></textarea>
            </td>
        </tr>
    </table>
</div>


